https://cloud.tencent.com/developer/ask/53091
新列分别显示年份和月份,可以这样做:
df['year'] = pd.DatetimeIndex(df['date']).year
df['month'] = pd.DatetimeIndex(df['date']).month
或者
df['year'] = df['date'].dt.year
df['month'] = df['date'].dt.month
https://cloud.tencent.com/developer/ask/53091
新列分别显示年份和月份,可以这样做:
df['year'] = pd.DatetimeIndex(df['date']).year
df['month'] = pd.DatetimeIndex(df['date']).month
或者
df['year'] = df['date'].dt.year
df['month'] = df['date'].dt.month